package com.platform.core.entity;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.platform.comm.entity.IdEntity;
import com.platform.comm.enums.YnEnum;
import com.platform.enums.ConfValueMode;
import com.platform.enums.converters.ConfValueModeConverter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;

/**
 * Description: 参数配置实体类
 *
 * @author libin Created on 2019/7/17
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "ncloud_sys_conf")
public class SysConf extends IdEntity {

    private static final long serialVersionUID = -6416213819880858985L;
    /**
     * 类别ID
     */
    @Column(name = "type_id", length = 36)
    private String typeId;

    /**
     * 设置编码
     */
    @Column(name = "conf_code", length = 100, nullable = false)
    private String confCode;

    /**
     * 完整编码
     */
    @Column(name = "route_code", length = 1024, nullable = false)
    private String routeCode;

    /**
     * 名称
     */
    @Column(name = "conf_name", length = 256, nullable = false)
    private String confName;


    @Column(name = "conf_value",columnDefinition = "jsonb")
    private String confValue;


    /**
     * 取值模式: 1: 字符串, 2：内部单选，3：内部多选，4：字典单选，5：字典多选
     */
    @Column(name = "value_mode", length = 1, nullable = false)
    @Convert(converter = ConfValueModeConverter.class)
    private ConfValueMode valueMode;


    @Type(type = "jsonb")
    @Column(name = "value_mapping",columnDefinition = "jsonb")
    private JsonNode valueMapping;


    /**
     * 字典项
     */
    @Column(name = "dict_name", length = 64)
    private String dictName;

    /**
     * 描述
     */
    @Column(name = "conf_desc", length = 1024)
    private String desc;

    /**
     * 排序编号
     */
    @Column(name = "sort_num")
    private Integer sortNum;

    /**
     * 状态 0：否，1：是
     */
    @Column(name = "delflag")
    private YnEnum delFlag;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_date", nullable = false, updatable = false)
    private LocalDateTime createDate;

    /**
     * 修改时间
     */
    @LastModifiedDate
    @Column(name = "update_date")
    private LocalDateTime updateDate;

    /**
     * 字典 KEY类型 字符串：string 数值：number
     */
    @Column(name = "key_type")
    private String keyType;
}
